<template>
  <div class="pharmacy-home">
    <!-- 头部 -->
    <header class="header">
      <div class="header-content">
        <div class="header-left">
          <span class="back-arrow" @click="goBack">‹</span>
          <span class="title">网上药房</span>
        </div>
        <div class="header-right">
          <span class="search-icon">🔍</span>
          <span class="cart-icon">🛒</span>
        </div>
      </div>
    </header>

    <!-- 促销横幅 -->
    <div class="promo-banner">
      <div class="banner-content">
        <div class="banner-left">
          <h2 class="discount-title">药品 30% 折扣</h2>
          <p class="discount-date">3月15-18日</p>
          <button class="order-btn">立即下单</button>
        </div>
        <div class="banner-right">
          <div class="doctor-illustration">
            <div class="doctor-figure">
              <div class="doctor-body"></div>
              <div class="doctor-head"></div>
              <div class="doctor-arm"></div>
              <div class="pill-in-hand"></div>
            </div>
            <div class="blister-pack">
              <div class="pills-container">
                <div class="pill-row" v-for="i in 5" :key="i">
                  <div class="pill" v-for="j in 2" :key="j"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="carousel-indicators">
        <div class="indicator active"></div>
        <div class="indicator"></div>
        <div class="indicator"></div>
      </div>
    </div>

    <!-- 分类部分 -->
    <section class="categories-section">
      <div class="section-header">
        <h3 class="section-title">分类</h3>
        <a href="#" class="view-all" @click="goToAllProducts">查看全部 ></a>
      </div>
      <div class="categories-grid">
        <div class="category-card" v-for="category in categories" :key="category.id">
          <div class="category-icon">
            <img :src="category.icon" :alt="category.label" class="category-img" />
          </div>
          <span class="category-label">{{ category.label }}</span>
        </div>
      </div>
    </section>

    <!-- 精选产品部分 -->
    <section class="products-section">
      <div class="section-header">
        <h3 class="section-title">精选产品</h3>
        <a href="#" class="view-all" @click="goToAllProducts">查看全部 ></a>
      </div>
      <div class="products-container">
        <div class="products-row">
          <div class="product-card" v-for="product in products.slice(0, 3)" :key="product.id" @click="goToProductDetail(product.id)">
            <div class="product-image-container">
              <img :src="product.image" :alt="product.name" class="product-image" />
              <div v-if="product.badge" class="product-badge" :class="product.badgeClass">
                {{ product.badge }}
              </div>
            </div>
            <div class="product-info">
              <div class="product-rating">
                <span class="star">⭐</span>
                <span class="rating-text">4.8 (256)</span>
              </div>
              <h4 class="product-name">{{ product.name }}</h4>
              <p class="product-quantity">{{ product.quantity }}</p>
              <p class="product-price">¥{{ product.price }}</p>
            </div>
          </div>
        </div>
        <div class="products-row">
          <div class="product-card" v-for="product in products.slice(3, 6)" :key="product.id" @click="goToProductDetail(product.id)">
            <div class="product-image-container">
              <img :src="product.image" :alt="product.name" class="product-image" />
              <div v-if="product.badge" class="product-badge" :class="product.badgeClass">
                {{ product.badge }}
              </div>
            </div>
            <div class="product-info">
              <div class="product-rating">
                <span class="star">⭐</span>
                <span class="rating-text">4.8 (256)</span>
              </div>
              <h4 class="product-name">{{ product.name }}</h4>
              <p class="product-quantity">{{ product.quantity }}</p>
              <p class="product-price">¥{{ product.price }}</p>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const goBack = () => {
  router.push('/home')
}

const goToAllProducts = () => {
  router.push('/all-products')
}

const goToProductDetail = (productId: number) => {
  router.push(`/product/${productId}`)
}

// 分类数据 - 使用imgs文件夹中的图片
const categories = ref([
  { 
    id: 1, 
    label: '处方药', 
    icon: new URL('./imgs/v2_sypct1.png', import.meta.url).href
  },
  { 
    id: 2, 
    label: '营养品', 
    icon: new URL('./imgs/v2_sypcsk.png', import.meta.url).href
  },
  { 
    id: 3, 
    label: '个人护理', 
    icon: new URL('./imgs/v2_sypcs4.png', import.meta.url).href
  },
  { 
    id: 4, 
    label: '家庭用药', 
    icon: new URL('./imgs/v2_sypcrj.png', import.meta.url).href
  },
  { 
    id: 5, 
    label: '医疗器械', 
    icon: new URL('./imgs/v2_sypcqe.png', import.meta.url).href
  },
  { 
    id: 6, 
    label: '性别健康', 
    icon: new URL('./imgs/v2_sypcq0.png', import.meta.url).href
  },
  { 
    id: 7, 
    label: '新冠肺炎', 
    icon: new URL('./imgs/v2_sypcpl.png', import.meta.url).href
  },
  { 
    id: 8, 
    label: '美容保养', 
    icon: new URL('./imgs/v2_sypczp.svg', import.meta.url).href
  }
])

// 产品数据 - 使用imgs文件夹中的图片
const products = ref([
  { 
    id: 1, 
    name: '多维元素片', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypcz0.svg', import.meta.url).href,
    badge: null,
    badgeClass: null
  },
  { 
    id: 2, 
    name: '朗迪碳酸钙', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypcy2.svg', import.meta.url).href,
    badge: '新品',
    badgeClass: 'new-badge'
  },
  { 
    id: 3, 
    name: '多维元素片', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypcxi.svg', import.meta.url).href,
    badge: '-30%',
    badgeClass: 'discount-badge'
  },
  { 
    id: 4, 
    name: '多维元素片', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypcwt.svg', import.meta.url).href,
    badge: null,
    badgeClass: null
  },
  { 
    id: 5, 
    name: '朗迪碳酸钙', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypczp.svg', import.meta.url).href,
    badge: '新品',
    badgeClass: 'new-badge'
  },
  { 
    id: 6, 
    name: '多维元素片', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypcz0.svg', import.meta.url).href,
    badge: '-30%',
    badgeClass: 'discount-badge'
  }
])
</script>

<style scoped>
.pharmacy-home {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(180deg, #4A90E2 0%, #4A90E2 25%, #ffffff 25%, #ffffff 100%);
  min-height: 100vh;
  padding-bottom: 20px;
}

/* 头部样式 */
.header {
  padding: 16px 20px 12px;
  color: white;
  box-shadow: 0 2px 12px rgba(74, 144, 226, 0.3);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-arrow {
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s ease;
}

.back-arrow:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.header-right {
  display: flex;
  gap: 20px;
}

.search-icon, .cart-icon {
  font-size: 22px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
  position: relative;
}

.search-icon:hover, .cart-icon:hover {
  background-color: rgba(255, 255, 255, 0.1);
  transform: scale(1.05);
}

.cart-icon::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: #FF6B6B;
  border-radius: 50%;
  border: 2px solid white;
}

/* 促销横幅样式 */
.promo-banner {
  margin: 0 16px 24px;
  position: relative;
}

.banner-content {
  background: linear-gradient(135deg, #FFE5E5 0%, #FFF0F0 100%);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.banner-left {
  flex: 1;
}

.discount-title {
  font-size: 24px;
  font-weight: bold;
  color: #333;
  margin: 0 0 8px 0;
}

.discount-date {
  font-size: 14px;
  color: #666;
  margin: 0 0 16px 0;
}

.order-btn {
  background: none;
  border: none;
  color: #4A90E2;
  text-decoration: underline;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.banner-right {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}

.doctor-illustration {
  position: relative;
  width: 120px;
  height: 120px;
}

.doctor-figure {
  position: relative;
  width: 80px;
  height: 100px;
}

.doctor-body {
  position: absolute;
  bottom: 0;
  left: 20px;
  width: 40px;
  height: 60px;
  background: #4A90E2;
  border-radius: 20px 20px 0 0;
}

.doctor-head {
  position: absolute;
  top: 0;
  left: 25px;
  width: 30px;
  height: 30px;
  background: #FFD700;
  border-radius: 50%;
}

.doctor-arm {
  position: absolute;
  bottom: 20px;
  right: 0;
  width: 20px;
  height: 40px;
  background: #4A90E2;
  border-radius: 10px;
  transform: rotate(-15deg);
}

.pill-in-hand {
  position: absolute;
  bottom: 10px;
  right: -10px;
  width: 12px;
  height: 12px;
  background: #FFD700;
  border-radius: 50%;
}

.blister-pack {
  position: absolute;
  right: 0;
  top: 20px;
  width: 40px;
  height: 80px;
  background: #E3F2FD;
  border-radius: 8px;
  border: 2px solid #BBDEFB;
}

.pills-container {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pill-row {
  display: flex;
  gap: 4px;
}

.pill {
  width: 8px;
  height: 8px;
  background: #FFD700;
  border-radius: 50%;
}

.carousel-indicators {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
}

.indicator.active {
  background: white;
}

/* 分类部分样式 */
.categories-section {
  padding: 0 16px 24px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin: 0;
}

.view-all {
  color: #4A90E2;
  text-decoration: none;
  font-size: 14px;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.category-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 8px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.category-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  overflow: hidden;
}

.category-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.category-label {
  font-size: 12px;
  color: #333;
  text-align: center;
  font-weight: 500;
}

/* 产品部分样式 */
.products-section {
  padding: 0 16px;
}

.products-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.products-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.product-card {
  min-width: 140px;
  background: white;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: relative;
}

.product-image-container {
  position: relative;
  margin-bottom: 8px;
}

.product-image {
  width: 100%;
  height: 100px;
  border-radius: 8px;
  object-fit: contain;
  background: #f8f9fa;
  padding: 6px;
}

.product-badge {
  position: absolute;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: bold;
  color: white;
}

.new-badge {
  background: #4CAF50;
  bottom: 4px;
  left: 4px;
}

.discount-badge {
  background: #4A90E2;
  top: 4px;
  left: 4px;
}

.product-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.product-rating {
  display: flex;
  align-items: center;
  gap: 4px;
}

.star {
  font-size: 12px;
}

.rating-text {
  font-size: 12px;
  color: #666;
}

.product-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin: 0;
  line-height: 1.2;
}

.product-quantity {
  font-size: 12px;
  color: #666;
  margin: 0;
}

.product-price {
  font-size: 16px;
  font-weight: bold;
  color: #F44336;
  margin: 0;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .header {
    padding: 12px 16px 8px;
  }
  
  .back-arrow {
    font-size: 24px;
    width: 28px;
    height: 28px;
  }
  
  .title {
    font-size: 18px;
  }
  
  .search-icon, .cart-icon {
    font-size: 20px;
    width: 32px;
    height: 32px;
  }
  
  .categories-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
  }
  
  .category-card {
    padding: 12px 6px;
  }
  
  .category-icon {
    width: 40px;
    height: 40px;
  }
  
  .product-card {
    min-width: 120px;
    padding: 10px;
  }
  
  .product-image {
    height: 85px;
    object-fit: contain;
    padding: 4px;
  }
}
</style>